package com.bjpowernode.service.impl;

import com.bjpowernode.constant.Constant;
import com.bjpowernode.entity.TClueRemark;
import com.bjpowernode.mapper.TClueRemarkMapper;
import com.bjpowernode.query.ClueRemarkQuery;
import com.bjpowernode.service.ClueRemarkService;
import com.bjpowernode.util.LoginInfoUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
@RequiredArgsConstructor
public class ClueRemarkServiceImpl implements ClueRemarkService {

    private final TClueRemarkMapper tClueRemarkMapper;

    @Override
    public int saveClueRemark(ClueRemarkQuery clueRemarkQuery) {
        TClueRemark tClueRemark = new TClueRemark();

        tClueRemark.setClueId(clueRemarkQuery.getClueId());
        tClueRemark.setNoteContent(clueRemarkQuery.getNoteContent());
        tClueRemark.setNoteWay(clueRemarkQuery.getNoteWay());

        tClueRemark.setCreateBy(LoginInfoUtil.getCurrentLoginUser().getId());
        tClueRemark.setCreateTime(new Date());

        return tClueRemarkMapper.insertSelective(tClueRemark);
    }

    @Override
    public PageInfo<TClueRemark> selectByPage(Integer clueId, Integer current) {
        PageHelper.startPage(current, Constant.PAGE_SIZE);
        List<TClueRemark> tClueRemarkList = tClueRemarkMapper.selectByPage(clueId);
        PageInfo<TClueRemark> pageInfo = new PageInfo<>(tClueRemarkList);
        return pageInfo;
    }
}
